var g_msg = "";
/**
 * 查询所有应用
 */
function getAllApp(jqElement) {
    jqElement.combobox({//应用
        method: 'get',
        url: contextPath + '/console/app/getAllApp',
        valueField: 'appCode',
        textField: 'appName',
        editable: false,
        panelHeight:　'auto',
        //:　'----请选择----',
        onLoadSuccess: function (data) {
            var cookieAppCode = $.cookie('logPage_appCode'); // appCode
            //var cookieAppCode = "monitorConsole";
            if (typeof cookieAppCode != "undefined"){
                if (data.length > 0){
                    for(var i =0 ;i<data.length;i++){
                        if(data[i].appCode==cookieAppCode){
                            jqElement.combobox('select', data[i].appCode);
                        }
                    }
                }
            }
        },
        onLoadError: function () {

        },
        onShowPanel: function () {
            $(this).combobox('panel').height();
        },
        onChange: function (newValue,oldValue) {

        }
    });
}


/**
 * 查询所有节点
 */
function getAllNode(jqElement,value) {
    jqElement.combobox({//应用
        method: 'get',
        url: contextPath + '/console/appNode/getAllNodeForLog?appCode='+value,
        valueField: 'node_code',
        textField: 'node_name',
        editable: false,
        panelHeight:　'auto',
        //:　'----请选择----',
        onLoadSuccess: function (data) {
            var cookieNodeCode = $.cookie('logPage_nodeCode'); // appCode
            if (data.length>0){
                jqElement.combobox('select', data[0].node_code);
                $.cookie('logPage_nodeCode', data[0].node_code, { expires: 30 });
            }
            if (typeof cookieNodeCode != "undefined"){
                if (data.length > 0){
                    for(var i =0 ;i<data.length;i++){
                        if(data[i].node_code==cookieNodeCode){
                            jqElement.combobox('select', data[i].node_code);
                        }
                    }
                }
            }
            // getLastId();
        },
        onLoadError: function () {

        },
        onShowPanel: function () {
            $(this).combobox('panel').height();
        },
        onChange: function (newValue,oldValue) {
            getTaskLog($("#taskCode"),newValue);
            $.cookie('logPage_nodeCode', newValue, { expires: 30 });
            g_msg = "";
            var data = jqElement.combobox('getData');
            for(var i =0 ;i<data.length;i++){
                if (data[i].node_code == newValue){
                    var node_status = data[i].status;
                    var host_status = data[i].host_status;
                    if (host_status == "0"){
                        g_msg = "主机已停用!";
                    }else if (host_status == "1" && node_status =="0"){
                        g_msg = "中间件已停用!";
                    }else if (host_status == "0" && node_status =="0"){
                        g_msg = "主机和中间件均已停用!";
                    }
                }
            }
            var str = "<li class='' style='border-bottom:none;padding:1px 4px 1px 30px;color: red;font-size: 18px'>"
                + "<span class='icon' ></span>"
                +g_msg +"</li>";
            $("#log_list_div").empty();
            $("#log_list_div").append(str);
            getLastId();
        }
    });
}



//获取日志任务.
function getTaskLog(jqElement,node_code) {
    jqElement.combobox({//应用
        method: 'get',
        url: contextPath + '/console/log/queryTask?node_code='+node_code,
        valueField: 'value',
        textField: 'task_name',
        editable: false,
        panelHeight:　'auto',
        //:　'----请选择----',
        onLoadSuccess: function (data) {
            var cookieTaskCode = $.cookie('logPage_taskCode');
            if (typeof cookieTaskCode != "undefined"){
                if (data.length > 0){
                    for(var i =0 ;i<data.length;i++){
                        if(data[i].value==cookieTaskCode){
                            jqElement.combobox('select', data[i].value);
                        }
                    }
                }
            }
        },
        onLoadError: function () {

        },
        onShowPanel: function () {
            $(this).combobox('panel').height();
        },
        onChange: function (newValue,oldValue) {
            getLastId();
            $.cookie('logPage_taskCode', newValue, { expires: 30 });
        }
    });
}
